<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class mdl_prosedur extends CI_Model {
    
	function __construct(){
        parent::__construct();
    }
	
	function OptionFakultas($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->from('ref_fakultas');
		$this->db->order_by('nama_fakultas');
		$this->db->where('status', 'A');
		
		#Kimochi - otoritas
		if($this->session->userdata('kd_fakultas')!=''){
			$this->db->where('kd_fakultas', $this->session->userdata('kd_fakultas'));
		}else{
			$out = '<option value="">-- Pilih --</option>';
		}
		#End Kimochi
		
		$res = $this->db->get();
		
		foreach($res->result() as $r){
			if(trim($r->kd_fakultas) == trim($value)){
				$out .= '<option value="'.$r->kd_fakultas.'" selected="selected">'.$r->nama_fakultas.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_fakultas.'">'.$r->nama_fakultas.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionProdi($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_prodi');
		$this->db->order_by('nama_prodi');
		
		#Kimochi - otoritas
		if($this->session->userdata('kd_fakultas')!=''){
			if($this->session->userdata('kd_prodi')!=''){
				$this->db->where('kd_fakultas', $this->session->userdata('kd_fakultas'));
				$this->db->where('kd_prodi', $this->session->userdata('kd_prodi'));
			}else{
				$this->db->where('kd_fakultas', $this->session->userdata('kd_fakultas'));
				$out = '<option value="">-- Pilih --</option>';
			}
		}else{
			$this->db->where('kd_fakultas', $kd_fakultas);
			$out = '<option value="">-- Pilih --</option>';
		}
		#End Kimochi
		
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		foreach($res->result() as $r){
			if(trim($r->kd_prodi) == trim($value)){
				$out .= '<option value="'.$r->kd_prodi.'" selected="selected">'.$r->nama_prodi.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_prodi.'">'.$r->nama_prodi.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionKurikulum($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_kurikulum');
		$this->db->order_by('nama_kurikulum');
		if($kd_prodi != ''){
			$this->db->where('kd_prodi', $kd_prodi);
		}
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_kurikulum) == trim($value)){
				$out .= '<option value="'.$r->kd_kurikulum.'" selected="selected">'.$r->nama_kurikulum.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_kurikulum.'">'.$r->nama_kurikulum.'</option>';
			}
		}
		
		return $out;
	}
	
	
	function OptionDosen($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_dosen');
		if($kd_prodi != ''){
			$this->db->where('kd_prodi', $kd_prodi);
		}
		$this->db->where('status', 'A');
		$this->db->order_by('nama_dosen');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_dosen) == trim($value)){
				$out .= '<option value="'.$r->kd_dosen.'" selected="selected">'.$r->nama_dosen.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_dosen.'">'.$r->nama_dosen.'</option>';
			}
		}
		
		return $out;
	}

	function OptionTahun($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_tahunajaran');
		$this->db->order_by('id_tahunajaran', 'DESC');
		$this->db->group_by('id_tahunajaran');
		$this->db->where('Status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->id_tahunajaran) == trim($value)){
				$out .= '<option value="'.$r->id_tahunajaran.'" selected="selected">'.$r->id_tahunajaran.'</option>';
			}else{
				$out .= '<option value="'.$r->id_tahunajaran.'">'.$r->id_tahunajaran.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionUniversitas($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_universitas');
		$this->db->where('status', 'A');
		$this->db->order_by('Nama');
		$this->db->where('Status', 'A');
		//$this->db->where('kd_pt', '121016');
		$res = $this->db->get();
		
		//$out = '<option value="">-- Pilih --</option>';
		$out = '';
		foreach($res->result() as $r){
			//if(trim($r->kd_pt) == trim($value)){
				$out .= '<option value="'.$r->kd_pt.'" selected="selected">'.$r->Nama.'</option>';
			//}
		}
		
		return $out;
	}
	
	function OptionKampus($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_kampus');
		$this->db->order_by('Nama');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_kampus) == trim($value)){
				$out .= '<option value="'.$r->kd_kampus.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_kampus.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionTahunAjaran($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_tahunajaran');
		$this->db->order_by('id_tahunajaran', 'DESC');
		$this->db->group_by('id_tahunajaran');
		$this->db->where('Status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->id_tahunajaran) == trim($value)){
				$out .= '<option value="'.$r->id_tahunajaran.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->id_tahunajaran.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}	

	function OptionComboMahasiswa($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_mahasiswa');
		$this->db->order_by('nim', 'ASC');
		
		#Kimochi - otoritas
		if($this->session->userdata('kd_prodi')!=''){
			$this->db->where('kd_prodi', $this->session->userdata('kd_prodi'));
		}else{
			if($kd_prodi != ''){
				$this->db->where('kd_prodi', $kd_prodi);
			}
		}
		#End Kimochi
		
		$res = $this->db->get();
		
		$out = array();
		$i=0;
		foreach($res->result() as $r){
			$out[$i]['nim'] = $r->nim;
			$out[$i]['nama'] = $r->nama;
			$i++;
		}
		
		return json_encode($out);
	}
	
	function OptionProgram($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_program');
		$this->db->order_by('Nama');
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_program) == trim($value)){
				$out .= '<option value="'.$r->kd_program.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_program.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionJenjang($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_jenjang');
		$this->db->order_by('Nama');
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_jenjang) == trim($value)){
				$out .= '<option value="'.$r->kd_jenjang.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_jenjang.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionFakultasByUniversitas($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_pt = isset($d['kd_pt'])?$d['kd_pt']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_fakultas');
		$this->db->order_by('nama_fakultas');
		if($kd_pt != ''){
			$this->db->where('kd_pt', $kd_pt);
		}
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_fakultas) == trim($value)){
				$out .= '<option value="'.$r->kd_fakultas.'" selected="selected">'.$r->nama_fakultas.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_fakultas.'">'.$r->nama_fakultas.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionProgramByUniversitas($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_pt = isset($d['kd_pt'])?$d['kd_pt']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_program');
		$this->db->order_by('Nama');
		if($kd_pt != ''){
			$this->db->where('kd_pt', $kd_pt);
		}
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_program) == trim($value)){
				$out .= '<option value="'.$r->kd_program.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_program.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionFakultasByUniv($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_pt = isset($d['kd_pt'])?$d['kd_pt']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_fakultas');
		$this->db->order_by('nama_fakultas');
		if($kd_pt != ''){
			$this->db->where('kd_pt', $kd_pt);
		}
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_fakultas) == trim($value)){
				$out .= '<option value="'.$r->kd_fakultas.'" selected="selected">'.$r->nama_fakultas.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_fakultas.'">'.$r->nama_fakultas.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionTahunAngkatan($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select ('thn_angkatan');
		$this->db->DISTINCT ();
		$this->db->from('tbl_mahasiswa');
		$this->db->order_by('thn_angkatan', 'ASC');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->thn_angkatan) == trim($value)){
				$out .= '<option value="'.$r->thn_angkatan.'" selected="selected">'.$r->thn_angkatan.'</option>';
			}else{
				$out .= '<option value="'.$r->thn_angkatan.'">'.$r->thn_angkatan.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionJabatan($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_jenisjabatan');
		$this->db->where('status', 'A');
		$this->db->order_by('Nama');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->JenisJabatanID) == trim($value)){
				$out .= '<option value="'.$r->JenisJabatanID.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->JenisJabatanID.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionTahunAkademikUp($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select('tahun_id');
		//$this->db->DISTINCT();
		$this->db->from('tbl_up');
		$this->db->order_by('tahun_id', 'ASC');
		$this->db->group_by('tahun_id');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->tahun_id) == trim($value)){
				$out .= '<option value="'.$r->tahun_id.'" selected="selected">'.$r->tahun_id.'</option>';
			}else{
				$out .= '<option value="'.$r->tahun_id.'">'.$r->tahun_id.'</option>';
			}
		}
		
		return $out;
	}
		
	function OptionJadwalPMB($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select ('PMBPeriodID');		
		$this->db->from('pmb_jadwal');
		$this->db->order_by('PMBPeriodID', 'ASC');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->PMBPeriodID) == trim($value)){
				$out .= '<option value="'.$r->PMBPeriodID.'" selected="selected">'.$r->PMBPeriodID.'</option>';
			}else{
				$out .= '<option value="'.$r->PMBPeriodID.'">'.$r->PMBPeriodID.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionMatakuliah($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_kurikulum = isset($d['kd_kurikulum'])?$d['kd_kurikulum']:'';
		
		$this->db->flush_cache();
		$this->db->select('*');		
		$this->db->from('ref_matakuliah');
		$this->db->where('kd_kurikulum', $kd_kurikulum);
		$this->db->where('status', 'A');
		$this->db->order_by('kd_matakuliah', 'ASC');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_matakuliah) == trim($value)){
				$out .= '<option value="'.$r->kd_matakuliah.'" selected="selected">'.$r->kd_matakuliah.' - '.$r->nama_matakuliah.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_matakuliah.'">'.$r->kd_matakuliah.' - '.$r->nama_matakuliah.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionRuang($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select('*');		
		$this->db->from('ref_ruang');
		$this->db->order_by('kd_ruang', 'ASC');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_ruang) == trim($value)){
				$out .= '<option value="'.$r->kd_ruang.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_ruang.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionJenisJadwal($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select('*');		
		$this->db->from('ref_jenisjadwal');
		$this->db->order_by('kd_jenisjadwal', 'ASC');
		$res = $this->db->get();
		
		$out = '';
		foreach($res->result() as $r){
			if(trim($r->kd_jenisjadwal) == trim($value)){
				$out .= '<option value="'.$r->kd_jenisjadwal.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_jenisjadwal.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionComboMahasiswa2($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_mahasiswa');
		$this->db->order_by('nim', 'ASC');
		if($kd_prodi != ''){
			$this->db->where('kd_prodi', $kd_prodi);
		}
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->nim) == trim($value)){
				$out .= '<option value="'.$r->nim.'" selected="selected">'.$r->nim.' - '.$r->nama.'</option>';
			}else{
				$out .= '<option value="'.$r->nim.'">'.$r->nim.' - '.$r->nama.'</option>';
			}
		}
		
		return $out;
	}

	//option dosen untuk Tugas Akhir
	function OptionDosenTa($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_dosen');
		
		#Kimochi - otoritas
		if($this->session->userdata('kd_prodi')!=''){
			$this->db->where('kd_prodi', $this->session->userdata('kd_prodi'));
		}else{
			if($kd_prodi != ''){
				$this->db->where('kd_prodi', $kd_prodi);
			}
		}
		#End Kimochi
		
		$this->db->order_by('nama_dosen');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->nama_dosen) == trim($value)){
				$out .= '<option value="'.$r->nama_dosen.'" selected="selected">'.$r->nama_dosen.'</option>';
			}else{
				$out .= '<option value="'.$r->nama_dosen.'">'.$r->nama_dosen.'</option>';
			}
		}
		
		return $out;
	}
	
	//option dosen table Nilai
	function OptionDosenNilai($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_matakuliah = isset($d['kd_matakuliah'])?$d['kd_matakuliah']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_dosen a');
		$this->db->join('tbl_jadwal b','b.kd_dosen = a.kd_dosen');
		//$this->db->join('tbl_jadwal b','b.kd_dosen = a.kd_dosen');
		if($kd_matakuliah != ''){
			$this->db->where('b.kd_matakuliah', $kd_matakuliah);
		}
		$this->db->group_by('a.kd_dosen');
		$this->db->order_by('nama_dosen');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->nama_dosen) == trim($value)){
				$out .= '<option value="'.$r->kd_dosen.'" selected="selected">'.$r->nama_dosen.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_dosen.'">'.$r->nama_dosen.'</option>';
			}
		}
		
		return $out;
	}
	
	//Option Kelas Dosen
	function OptionKelasNilai($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_dosen = isset($d['kd_dosen'])?$d['kd_dosen']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_jadwal');
		$this->db->order_by('kd_kelas');
		if($kd_dosen != ''){
			$this->db->where('kd_dosen', $kd_dosen);
		}
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_kelas) == trim($value)){
				$out .= '<option value="'.$r->kd_kelas.'" selected="selected">'.$r->kd_kelas.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_kelas.'">'.$r->kd_kelas.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionOtoritas($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->from('sys_user_level');
		
		$this->db->order_by('level');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->user_level_id) == trim($value)){
				$out .= '<option value="'.$r->user_level_id.'" selected="selected">'.$r->level_name.'</option>';
			}else{
				$out .= '<option value="'.$r->user_level_id.'">'.$r->level_name.'</option>';
			}
		}
		
		return $out;
	}
	//cobo mahasiswa up=lulus
	function OptionComboMahasiswabyUp($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		
		$this->db->from('tbl_up a');
		$this->db->join('tbl_mahasiswa b','b.nim=a.nim');
		$this->db->where('a.proposal', "Lulus");
		$this->db->where('a.status', "A");
		$this->db->order_by('a.nim', 'ASC');
		if($kd_prodi != ''){
			$this->db->where('b.kd_prodi', $kd_prodi);
		}
		$res = $this->db->get();
		
		$out = array();
		$i=0;
		foreach($res->result() as $r){
			$out[$i]['nim'] = $r->nim;
			$out[$i]['nama'] = $r->nama;
			$i++;
		}
		
		return json_encode($out);
	}
	//cobo mahasiswa yg sudah seminar
	function OptionComboMahasiswabySeminar($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		
		$this->db->from('tbl_seminar a');
		$this->db->join('tbl_mahasiswa b','b.nim=a.nim');
		$this->db->where('a.tgl_seminar2 is not null');
		$this->db->where('a.status', "A");
		$this->db->order_by('a.nim', 'ASC');
		if($kd_prodi != ''){
			$this->db->where('b.kd_prodi', $kd_prodi);
		}
		$res = $this->db->get();
		
		$out = array();
		$i=0;
		foreach($res->result() as $r){
			$out[$i]['nim'] = $r->nim;
			$out[$i]['nama'] = $r->nama;
			$i++;
		}
		
		return json_encode($out);
	}
	//tahun akademik untuk seminar
	function OptionTahunakademikSeminar($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select ('tahun_id');
		$this->db->DISTINCT ();
		$this->db->from('tbl_seminar');
		$this->db->order_by('tahun_id', 'ASC');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->tahun_id) == trim($value)){
				$out .= '<option value="'.$r->tahun_id.'" selected="selected">'.$r->tahun_id.'</option>';
			}else{
				$out .= '<option value="'.$r->tahun_id.'">'.$r->tahun_id.'</option>';
			}
		}
		
		return $out;
	}
	//tahun akademik untuk sidang
	function OptionTahunakademikSidang($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select ('tahun_id');
		$this->db->DISTINCT ();
		$this->db->from('tbl_sidang');
		$this->db->order_by('tahun_id', 'ASC');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->tahun_id) == trim($value)){
				$out .= '<option value="'.$r->tahun_id.'" selected="selected">'.$r->tahun_id.'</option>';
			}else{
				$out .= '<option value="'.$r->tahun_id.'">'.$r->tahun_id.'</option>';
			}
		}
		
		return $out;
	}
	
	//Tahun anggkatan untuk mutasi mahasiswa
	function OptionTahunAngkatanM($d=""){
		$value = isset($d['value'])?$d['value']:'';
		
		$this->db->flush_cache();
		$this->db->select ('thn_angkatan');
		$this->db->DISTINCT ();
		$this->db->from('tbl_mutasi_mahasiswa');
		$this->db->order_by('thn_angkatan', 'ASC');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->thn_angkatan) == trim($value)){
				$out .= '<option value="'.$r->thn_angkatan.'" selected="selected">'.$r->thn_angkatan.'</option>';
			}else{
				$out .= '<option value="'.$r->thn_angkatan.'">'.$r->thn_angkatan.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionJenisMK($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_jenismk = isset($d['kd_jenismk'])?$d['kd_jenismk']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_mkjenis');
		$this->db->order_by('Nama');
		if($kd_jenismk != ''){
			$this->db->where('kd_jenismk', $kd_jenismk);
		}
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_jenismk) == trim($value)){
				$out .= '<option value="'.$r->kd_jenismk.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_jenismk.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionKelompokMK($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_kelompokmk = isset($d['kd_kelompokmk'])?$d['kd_kelompokmk']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_mkkelompok');
		$this->db->order_by('Nama');
		if($kd_kelompokmk != ''){
			$this->db->where('kd_kelompokmk', $kd_kelompokmk);
		}
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_kelompokmk) == trim($value)){
				$out .= '<option value="'.$r->kd_kelompokmk.'" selected="selected">'.$r->Nama.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_kelompokmk.'">'.$r->Nama.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionGedung($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_kampus = isset($d['kd_kampus'])?$d['kd_kampus']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_gedung');
		$this->db->order_by('nama_gedung');
		if($kd_kampus != ''){
			$this->db->where('kd_kampus', $kd_kampus);
		}
		$this->db->where('status', 'A');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_gedung) == trim($value)){
				$out .= '<option value="'.$r->kd_gedung.'" selected="selected">'.$r->nama_gedung.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_gedung.'">'.$r->nama_gedung.'</option>';
			}
		}
		
		return $out;
	}
	
	//option mahasiswa mutasi
	function OptionComboMutasiMahasiswa($d=""){
	
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('tbl_mutasi_mahasiswa');
		$this->db->where('verifikasi','Sudah');
		$this->db->order_by('nim', 'ASC');
		if($kd_prodi != ''){
			$this->db->where('kd_prodi', $kd_prodi);
		}
		$res = $this->db->get();
		
		$out = array();
		$i=0;
		foreach($res->result() as $r){
			$out[$i]['nim'] = $r->nim;
			$out[$i]['nama'] = $r->nama;
			$i++;
		}
		
		return json_encode($out);
	}
	
	function getKodePT(){
		$this->db->flush_cache();
		$this->db->select('kd_pt');
		$this->db->from('ref_universitas');
		
		$r = $this->db->get();
		
		if($r->num_rows()>0){
			return $r->row()->kd_pt;
		}else{
			return '';//121016
		}
	}
	//cobo mahasiswa yg sudah seminar1
	function OptionComboMahasiswabySeminar1($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		
		$this->db->from('tbl_seminar a');
		$this->db->join('tbl_mahasiswa b','b.nim=a.nim');
		$this->db->where('a.tgl_seminar1 is not null');
		$this->db->where('a.status', "A");
		$this->db->order_by('a.nim', 'ASC');
		if($kd_prodi != ''){
			$this->db->where('b.kd_prodi', $kd_prodi);
		}
		$res = $this->db->get();
		
		$out = array();
		$i=0;
		foreach($res->result() as $r){
			$out[$i]['nim'] = $r->nim;
			$out[$i]['nama'] = $r->nama;
			$i++;
		}
		
		return json_encode($out);
	}
	//combo mhs yang ambil ta di krs
	function OptionComboMahasiswaAmbilTa($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('v_mhs_ambil_ta');
		$this->db->order_by('nim', 'ASC');
		
		#Kimochi - otoritas
		if($this->session->userdata('kd_prodi')!=''){
			$this->db->where('kd_prodi', $this->session->userdata('kd_prodi'));
		}else{
			if($kd_prodi != ''){
				$this->db->where('kd_prodi', $kd_prodi);
			}
		}
		#End Kimochi
		
		$res = $this->db->get();
		
		$out = array();
		$i=0;
		foreach($res->result() as $r){
			$out[$i]['nim'] = $r->nim;
			$out[$i]['nama'] = $r->nama;
			$i++;
		}
		
		return json_encode($out);
	}
	
	function OptionDosenWali($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prodi = isset($d['kd_prodi'])?$d['kd_prodi']:'';
		//$kd_fakultas = isset($d['kd_fakultas'])?$d['kd_fakultas']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_dosen');
		if($kd_prodi != ''){
			$this->db->where('kd_prodi', $kd_prodi);
		}
		$this->db->where('dosen_wali', 'A');
		$this->db->where('status', 'A');
		$this->db->order_by('nama_dosen');
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_dosen) == trim($value)){
				$out .= '<option value="'.$r->kd_dosen.'" selected="selected">'.$r->nama_dosen.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_dosen.'">'.$r->nama_dosen.'</option>';
			}
		}
		
		return $out;
	}
	
	function OptionKota($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$out = '';
		
		$this->db->flush_cache();
		$this->db->from('ref_provinsi');
		$this->db->order_by('kd_prov');
		
		$res = $this->db->get();
		
		$out .= '<option value="">-- Pilih Provinsi --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_prov) == trim($value)){
				$out .= '<option value="'.$r->kd_prov.'" selected="selected">'.$r->nama_prov.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_prov.'">'.$r->nama_prov.'</option>';
			}
		}
		
		return $out;
	}
	
	//Update Provinsi Kabupaten
	function OptionKabup($d=""){
		$value = isset($d['value'])?$d['value']:'';
		$kd_prov = isset($d['kd_prov'])?$d['kd_prov']:'';
		
		$this->db->flush_cache();
		$this->db->from('ref_kabupaten');
		$this->db->order_by('nama_kabup');
		if($kd_prov != ''){
			$this->db->where('kd_prov', $kd_prov);
		}
		$res = $this->db->get();
		
		$out = '<option value="">-- Pilih Kota/Kabupaten --</option>';
		foreach($res->result() as $r){
			if(trim($r->kd_kabup) == trim($value)){
				$out .= '<option value="'.$r->kd_kabup.'" selected="selected">'.$r->nama_kabup.'</option>';
			}else{
				$out .= '<option value="'.$r->kd_kabup.'">'.$r->nama_kabup.'</option>';
			}
		}
		
		return $out;
	}
	
}

?>